/*
 *  制作人：xu;
 *  完成时间：2016.5.17;
 *	自制jq小型库，带有简单的jq方法。
 *	选择器： 只有派生选择器 如：$('#box ul li'),可以传递对象和函数进去，$(document), $(function)
 *	对象的方法分为几类： 查找dom节点、操作dom节点、操作dom样式、浏览器窗体行为、事件处理
 *	还有一些工具方法；
 *	此库的核心：carousel方法（旋转轮播）
 *	 HTML格式：
 *				
 *		<div id="box">
 *			<ul>
 *				<li><img src="1.png"></li>
 *				<li><img src="2.png"></li>
 *				<li><img src="3.png"></li>
 *				<li><img src="4.png"></li>
 *			</ul>
 *			<a>&lsaquo;</a>
 *			<a>&rsaquo;</a>
 *		</div>	
 *
 *			
 *		js 格式：{
 *			$('#box').carousel();
 *		},
 *		可以对内置参数加以修改：
 *		$('#box ul').carousel({
 *			method:'middle' //对齐方式： 'top','bottom','middle' 
 *			scale : 0.9    // 缩放比例： 0.8 , 0.7 ..
 *			autoPlayer : true	//自动播放： false,true
 *			timeout : 5000		//自动间隔： 3000 ,4000...
 *			btnStatetBg :'rgba(200,200,200,0.1)'  //按钮静止背景色： 请使用rgba格式
 *			btnActiveBg :'rgba(155,155,155,0.2)'  //按钮覆盖鼠标时背景色：同上
 *		});
 *	轮播器规则：图片必须一致大小；对ul执行轮播方法；所有样式内置，手动添加css无效；ul必须有父元素盒子；
 *	
 *		
 */


;(function(){
	
	var Xu = function(selector) {
		return new Xu.fn.init(selector);
	}
	var	idExp = /^\s*\#/;
	var indexOf = Array.prototype.indexOf;
	Xu.objCache = [];
	Xu.fn = Xu.prototype = {
		constructor : Xu,
		init : function(selector) {
			if( typeof selector === 'string' ) {
				var selectList = selector.split(/\s+/);
				if( idExp.test(selectList[0]) ) {
					this.context = Xu.id( selectList[0].substring(1) );
					this.selector = selectList[0];
					selectList = selectList.slice(1);
				}else {
					this.selector = '';
					this.context = document;
				}
				this.length =1;
				this[0] = this.context;
				this.find(selectList);
			}else if( typeof selector === 'object' ) {
				if( $.objCache.length === 0 ) {
					this.selector = selector === window ? 'window':'document';
					this.context = selector;
					this[0] = selector;
					this.length = 1;
				}else {
					for(var i=0; i<$.objCache.length; i++) {
						var oldObj = $.objCache[i];
						var index = indexOf.call(oldObj,selector);
						if( index !== -1) {
							this.selector = oldObj.selector;
							this.context = oldObj.selector;
							this[0] = oldObj[index];
							this.length = 1;
						}
					}
				}
			}else if(typeof selector === 'function') {
				Xu.ready(selector);
			}
			return this;
		}
	}

	//继承机制
	Xu.extend = Xu.fn.extend = function() {
		var target, copy , id,i =1,midd ;
		target = arguments[0] || {}
		if( arguments.length == i ) {
			target = this;
			i--;
		}
		for(; i < arguments.length ; i++) {
			midd = arguments[i];
			for(id in midd) {
				copy = midd[id];
				target[id] = copy;
			}
		}
		return this;
	}

	//加载页面
	Xu.ready = function(func) {
		if( Xu.isIE() ) {			//ie的方法
			var timer = null;
			timer = setInterval(function(){
				try{
					document.documentElement.doScroll('left');
					fun();
				}catch(e){}
			},1);
		}else {
			document.addEventListener('DOMContentLoaded',func,false);
		}
	}



	//对象查找dom方法
	Xu.fn.extend({
		find: function(selectList) {
			if(typeof selectList == 'string' ){
				 selectList = [selectList];
			}
			if( selectList.length === 0 )	{
				this[0] = this.context;
				return;
			}
			var  parents = [],nodeList=[],nodes=[],sel,oldLen = this.length , i,j,k;
			for(i = 0 ; i < oldLen; i++) {
				parents[i] = this[i];
			}
			this.context = parents[0];
			for(i=0 ;i<selectList.length; i++) {
				sel = selectList[i];
				this.selector += ' '+sel;
				switch( sel.charAt(0) ){
					case '.' : 
						nodeList = [];
						for(j=0; j<parents.length; j++) {
							nodes = Xu.clas(sel.substring(1),parents[j]);
							for(k=0; k< nodes.length; k++ ) {
								nodeList.push(nodes[k]);
							}
						}
						parents = nodeList;
					break;
					default : 
						nodeList = [];
						for(j=0; j<parents.length; j++) {
							nodes = Xu.tag(sel,parents[j]);
							for(k=0; k< nodes.length; k++ ) {
								nodeList.push(nodes[k]);
							}
						}
						parents = nodeList;
					break;
				}
			}
			len = nodeList.length;
			
			if( len === 0 ) {
				this.length = 0;
				for(i=0; i<oldLen; i++) {
					delete this[i];
				}
			}else {
				this.length = len;
				for(i=0; i<oldLen; i++) {
					delete this[i];
				}
				for(i=0; i<len; i++) {
					this[i] = nodeList[i];
				}
			}
			this.selector = $.trim(this.selector);
			Xu.addObjCache(this);
			//console.log(this)
			//console.log($.objCache)
			return this;
		},
		eq : function(index) {
			var ret = Xu();
			ret[0] = this[index];
			ret.length =1;
			ret.selector = this.selector +':nth-child('+index+')';
			ret.context = this.context;
			return ret;
		},
		get : function(index) {
			return this[index];
		},
		first: function() {
			var ret = Xu();
			ret[0] = this[0];
			ret.length =1;
			ret.selector =this.selector + ':first';
			ret.context =this.context;
			return ret;
		},
		last: function() {
			var ret = Xu();
			ret[0] = this[this.length-1];
			ret.length =1;
			ret.selector = this.selector + ':last';
			ret.context =this.context;
			return ret;
		},
		next: function() {
			var ret = Xu();
			var obj = $.objCache[$.objCache.length-1];
			for(var i=0; i<obj.length; i++) {
				if( obj[i] === this[0]) {
					ret[0] = obj[i+1];
					break;
				}
			}
			ret.length = 1;
			ret.selector = this.selector+':next';
			ret.context =this.context;
			return ret;
		},
		prev: function() {
			var ret = Xu();
			var obj = $.objCache[$.objCache.length-1];
			for(var i=0; i<obj.length; i++) {
				if( obj[i] === this[0]) {
					ret[0] = obj[i-1];
					break;
				}
			}
			ret.length = 1;
			ret.selector = this.selector+':prev';
			ret.context =this.context;
			return ret;
		},
		children: function() {
			var ret = Xu(),len=0;
			var chilNodes = [] , nodeList;
			for(var i=0; i<this.length; i++) {
				nodeList = this[0].children;
				for(var j=0; j<nodeList.length; j++) {
					ret[len++] = nodeList[j];
				}
			}
			ret.length = len;
			ret.context = this.context;
			ret.selector = this.selector+':children';

			return ret;
		},
		siblings:function() {
			var ret = Xu(), i=0, j=0, k=0, parent, childs=[] ,otherChild=[];
			for(; i<this.length; i++) {
				parent = this[i].parentNode;
				childs = parent.children;
				for(j=0; j<childs.length; j++) {
					if(childs[j] !== this[i]) {
						otherChild.push(childs[j]);
						ret[k++] = childs[j];
					}
				}
			}
			ret.selector = this.selector +':siblings';
			ret.context = this.context;
			ret.length = k; 
			Xu.addObjCache(ret);
			return ret;
		}
	})
	
	//其他对象方法
	Xu.fn.extend({
		index: function() {	
			var i=0, j=0, obj, objCache = $.objCache;
			for(;i<objCache.length;i++) {
				obj = objCache[i];
				index = indexOf.call(obj,this[0])
				if(index !== -1) {
					return index;
				}
			}
			return '';
		},
		each:function(func) {
			for(var i=0; i<this.length; i++) {
				func.call(this[i],this[i],i);
			}
			return this;
		}
	})

	//内部工具方法
	Xu.extend({
		id: function(id) {
			return document.getElementById(id);
		},
		tag: function(tag,parent) {
			if( !parent ) parent = document;
			return parent.getElementsByTagName(tag);
		},
		clas:function(clas,parent) {
			var all = Xu.tag('*',parent) , elem=[];
			for(var i=0,len=all.length; i<len; i++) {
				if( all[i].className.indexOf(clas) != -1) {
					elem.push(all[i]);
				}
			}
			return elem;
		},
		hasClass : function(elem,str) {
			return elem.className.indexOf(str) === -1 ? false:true;
		},
		addClass: function(elem,str) {
			if(!Xu.hasClass(elem,str) ) {
				elem.className += ' '+str;
			}
		},
		removeClass:function(elem,str) {
			elem.className = elem.className.replace(str,'');
		},
		getStyle : function(elem,attr) {
			return window.getComputedStyle ? getComputedStyle(elem,null)[attr] : elem.currentStyle[attr];
		},
		addEvent:function(obj,type,fun) {
			(function(obj,type,fun){
				function addEvent(obj,type,fun){
					if( typeof obj.addEventListener != 'undefined' ){
						return obj.addEventListener(type,fun, false);
					}else{
						if( !obj.events ) obj.events = {};
						if( !obj.events[type] ){
							obj.events[type] = [];
							if( obj['on' + type] ) obj.events[type][0].fun;
						}else{
							if ( this.equal(obj.events[type], fun) ) return false;
						}
						obj.events[type][this.ID++] = fun;
						obj['on'+type] = this.exec;
					}
				}
				addEvent.prototype ={
					ID : 1,
					exec : function(event){
						var e = event || this.fixEvent(window.event);
						var es = this.events[e.type];
						for(var g in es) es[g].call(this,e);
					},
					equal : function(es , fun){
						for(var i in es){
							if(es[i] == fun) return true;
						}
						return false;
					},
					fixEvent : function(event){
						event.preventDefault = this.fixEventPreventDefault;
						event.stopPropagation = this.fixEventStopPropagation;
						event.target = event.srcElement;
						return event;
					},
					fixEventPreventDefault : function(){
						this.returnValue = false;
					},
					fixEventStopPropagation : function(){
						this.cancelBubble = true;
					}
				}
				new addEvent(obj,type,fun);
			})(obj,type,fun);
		},
		removeEvent:function(obj,type,fun) {
			return function (obj,type,fun){
				if( typeof obj.removeEventListener != 'undefined' ){
					return obj.removeEventListener(type,fun ,false);
				}else if( obj.event ){
						for( var i in obj.events[type] ){
							if( obj.events[type][i] == fun ) delete obj.events[type][i];
						}
					}
			}(obj,type,fun);
		},
		trim:function(str) {
			return str.replace(/(^\s*)|(\s*$)/g,'');
		},
		createElement:function (tag){
			var elem = document.createElement(tag);
			return elem;
		},
		isIE:function() {
			return !-[1,];
		},
		addObjCache:function(that) {
			var adds = true;
			for(i=0; i<$.objCache.length; i++) {			//添加Xu对象容器
				if( $.objCache[i].selector === that.selector ){
					adds = false;
				}
			}
			if(adds){
				$.objCache.push(that);
			}
		}
		
	});

	//外部窗口公共方法
	Xu.extend({
		center : function(target){
			var screen_width = document.documentElement.clientWidth;
			var screen_height = document.documentElement.clientHeight;
			for(var i = 0; i < target.length; i++){

				var elem = target[i];
				//alert(elem)
				var width = parseInt(Xu.getStyle(elem,'width'));
				var height = parseInt( Xu.getStyle(elem,'height') );
				if( Xu.getStyle(elem,'position') === 'static'){
					elem.style.position = 'fixed';
				}
				elem.style.top = (screen_height - height)/2 + 'px';
				elem.style.left = (screen_width - width)/2 +'px';
			}
		},
		stopScroll:function() {
			document.documentElement.scrollTop = 0;
			document.body.scrollTop = 0;
		},
		resize: function(func) {			//不兼容ie8
			Xu.addEvent(window,'resize',func.bind(this));
		},
		lock : function(elem,zIndex){
			if( zIndex === undefined ){
				zIndex = elem;
				elem = Xu.createElement('div');
				elem.className = 'xu-locked';
				document.body.appendChild(elem);
			}
			var width = window.innerWidth ? window.innerWidth + 'px' : 
						document.documentElement.clientWidth + 'px';
			var height = window.innerHeight ? window.innerHeight + 'px' :
						 document.documentElement.clientHeight + 'px';
			elem.style.height = height;
			elem.style.width = width;
			elem.style.display = 'block';
			elem.style.position = 'fixed';
			elem.style.backgroundColor = '#ccc';
			elem.style.top = '0';
			elem.style.left = '0';
			elem.style.zIndex = zIndex;
			//		在遮罩时屏幕不可改变大小
			Xu.addEvent(window , 'scroll' ,Xu.stopScroll );
		},
		unlock:function(elem){
			if( elem === undefined ){
				elem = Xu.clas('xu-locked')[0];
			}
			elem.style.display = 'none';
			Xu.removeEvent(window,'scroll', Xu.stopScroll);
		}
	})
	

	//对象中的 窗口事件
	Xu.fn.extend({
		center : function(){
			Xu.center(this);
			return this;
		},
		resize: function(func) {			//不兼容ie8
			Xu.addEvent(window,'resize',func.bind(this));
			return this;
		},
		lock:function(zIndex) {
			zIndex = zIndex || '8';
			Xu.lock(this[0],zIndex);
			return this;
		},
		unlock:function(){
			Xu.unlock(elem);
			return this;
		}

	})

	//Xu对象中的dom操作方法
	Xu.fn.extend({
		html : function(str) {
			if( str === undefined ) {
				return this[0].innerHTML;
			}
			for(var i=0; i<this.length; i++) {
				this[i].innerHTML = str;
			}
			return this;
		},
		text : function(str) {
			if(str === undefined) {
				return this[0].textContent || this[0].innerText;
			}
			for(var i=0; i<this.length; i++) {
				this[i].innerText = this[i].textContent = str;
			}
			return this;
		},
		attr : function(key,value) {
			if(value === undefined) {
				return this[0].getAttribute(key);
			}
			for(var i=0; i<this.length; i++) {
				this[i].setAttribute(key,value);
			}
			return this;
		},
		val:function(value) {		//	-----------------------------未完成 ，radio checkbox 时
			if(value === undefined) {
				return this[0].value;
			}
			for(var i=0; i<this.length; i++) {
				this[i].value = value;
			}
			return this;
		},
		hasClass: function(str) {
			return Xu.hasClass(this[0],str);
		},
		addClass: function(str) {
			for(var i=0; i<this.length; i++) {
				Xu.addClass(this[i],str);
			}
			return this;
		},
		removeClass:function(str) {
			for(var i=0; i<this.length; i++) {
				Xu.removeClass(this[i],str);
			}
			return this;
		},
		toggleClass: function(str) {
			var elem;
			for(var i=0; i<this.length; i++) {
				elem = this[i];
				if( new RegExp('(\\s+|^)'+str+'(\\s+|$)').test(elem.className) ) {
					Xu.removeClass(elem,str);
				}else {
					Xu.addClass(elem,str);
				}
			}
			return this;
		}
	})
	
	//Xu内部数据存储
	var dataCache = {};
	Xu.extend({
		data : function(elem,key,value) {
			if( value === undefined ) {
				return dataCache.elem.key;
			}else {
				dataCache.elem = {};
				dataCache.elem.key = value;
			}
		}
	})

	//Xu对象 对css的操作
	Xu.fn.extend({
		css : function(attr,value) {
			var i,len=this.length;
			if(typeof attr === 'string') {
				if( value === undefined ) {
					return Xu.getStyle(this[0],attr);
				}else {
					for(i=0; i<len; i++) {

						this[i].style[attr] = value;
					}
				}
			}else if(typeof attr === 'object') {
				for(i=0; i<len; i++) {
					for(var key in attr ) {
						this[i].style[key] = attr[key];
					}
				}

			}
			return this;
		},
		color: function(val) {
			if(val === undefined) {
				return Xu.getStyle(this[0],'color');
			}
			for(var i=0; i<this.length; i++) {
				this[i].style.color = val;
			}
			return this;
		},
		bgColor: function(val) {
			if(val === undefined) {
				return Xu.getStyle(this[0],'backgroundColor');
			}
			for(var i=0; i<this.length; i++) {
				this[i].style.backgroundColor = val;
			}
			return this;
		},
		show : function() {
			if( Xu.getStyle(this[0],'display') === 'none' ) {
				for(var i=0; i<this.length; i++) {
					this[i].style.display =  Xu.data(this[i],'display') || '';
				}
			}
			return this;
		},
		hide: function() {
			for(var i=0; i<this.length; i++) {
				Xu.data(this[i], 'display' ,Xu.getStyle(this[i],'display'));
				this[i].style.display = 'none';
			}
			return this;
		},
		height: function(val){
			if(val === undefined) {
				return parseInt( Xu.getStyle(this[0],'height') );		
			}else{
				if(+val >= 0){
					for(var i=0; i<this.length; i++) {
						this[i].style.height = val+'px';
					}
				}else {
					throw '参数错误！';
				}
			}	
			return this;
		},
		width: function(val){
			if(val === undefined) {
				return parseInt( Xu.getStyle(this[0],'width') );		
			}else{
				if(+val >= 0){
					for(var i=0; i<this.length; i++) {
						this[i].style.width = val+'px';
					}
				}else {
					throw '参数错误！';
				}
			}	
			return this;
		},
		offset:function(){
			return { 
				width : this[0].offsetWidth,
				height : this[0].offsetHeight,
				left : this[0].offsetLeft,
				top : this[0].offsetTop
			}
		}


	});
	

	//对象的事件

	Xu.fn.extend({
		click : function(func) {
			for(var i=0; i<this.length; i++) {
				Xu.addEvent(this[i],'click',func);
			}
			return this;
		},
		mouseover:function(func) {
			for(var i=0; i<this.length; i++) {
				Xu.addEvent(this[i],'mouseover',func);
			}
			return this;
		},
		mouseout:function(func) {
			for(var i=0; i<this.length; i++) {
				Xu.addEvent(this[i],'mouseout',func);
			}
			return this;
		},
		mouseenter:function(func) {
			for(var i=0; i<this.length; i++) {
				Xu.addEvent(this[i],'mouseenter',func);
			}
			return this;
		},
		mouseleave:function(func) {
			for(var i=0; i<this.length; i++) {
				Xu.addEvent(this[i],'mouseleave',func);
			}
			return this;
		},
		mousedown:function(func) {
			for(var i=0; i<this.length; i++) {
				Xu.addEvent(this[i],'mousedown',func);
			}
			return this;
		},
		mouseup:function(func) {
			for(var i=0; i<this.length; i++) {
				Xu.addEvent(this[i],'mouseup',func);
			}
			return this;
		},
		mousemove:function(func) {
			for(var i=0; i<this.length; i++) {
				Xu.addEvent(this[i],'mousemove',func);
			}
			return this;
		},
		keydown:function(func) {
			for(var i=0; i<this.length; i++) {
				Xu.addEvent(this[i],'keydown',func);
			}
			return this;
		},
		keyup:function(func) {
			for(var i=0; i<this.length; i++) {
				Xu.addEvent(this[i],'keyup',func);
			}
			return this;
		},
		focus:function(func) {
			for(var i=0; i<this.length; i++) {
				Xu.addEvent(this[i],'focus',func);
			}
			return this;
		},
		blur:function(func) {
			for(var i=0; i<this.length; i++) {
				Xu.addEvent(this[i],'blur',func);
			}
			return this;
		},

		

		on : function(type,func) {
			for(var i=0; i<this.length; i++) {
				Xu.addEvent(this[i],type,func);
			}
			return this;
		},
		off:function(type,func) {
			for(var i=0; i<this.length; i++) {
				Xu.removeEvent(this[i],type,func);
			}
			return this;
		}
	})
	





	
	//旋转木马轮播

	Xu.extend({
		carousel: function(elem,obj) {
			(function(ele,obj){
			function Carousel(obj) {
				this.self =Xu;
				var ul = this.getTag('ul',ele)[0],
					oLi = this.getTag('li',ul),
					ulPar = ele,
					oneImg = this.getTag('img',oLi[0])[0],
					forwordBtn = this.getTag('a',ulPar)[1],
					backBtn = this.getTag('a',ulPar)[0],
					imgW = oneImg.offsetWidth,
					imgH = oneImg.offsetHeight,
					len = oLi.length,
					ulW = parseInt(this.self.getStyle(ulPar,'width'));
				this.elemInfo = {
					ulPar : ulPar,
					oUl : ul,
					oLi : oLi,
					oneImg: oneImg,
					forwordBtn : forwordBtn,
					backBtn : backBtn,

					liW: imgW,
					liH : imgH,
					ulW : ulW,
					btnW : (ulW-imgW)/2,

					len :len ,
					midd : Math.floor(len/2),
					sIndex : 0,
					zIdx : len%2 != 0 ? Math.ceil(len/2) : len/2+1,
					lGroup : [],
					rGroup:[],

				};
				this.initInfo = {
					method : 'middle',
					scale: 0.8,
					btnStatetBg :'rgba(200,200,200,0.2)',
					btnActiveBg :'rgba(155,155,155,0.3)',
					autoPlayer : false,
					timeout : 3000
				};
				this.extendInfo(obj);
				this.setElements();
				this.group();
				this.initSet();
				this.setEvent();
				this.autoPlayer(this.initInfo.autoPlayer);
			}

			Carousel.prototype = {
				//继承用户配置的参数
				extendInfo : function(outObj) {
					for(var i in outObj) {
						if( i in this.initInfo ) {
							this.initInfo[i] = outObj[i];
						}
					}
				},
				//设置轮播框架元素css样式
				setElements : function() {

					var _this = this;
					this.elemInfo.ulPar.style.position = 'relative';
					this.elemInfo.ulPar.style.width = this.elemInfo.ulW + 'px';
					this.elemInfo.oUl.style.cssText = "width:"+this.elemInfo.ulW + 'px;height:'+
					this.elemInfo.liH +
						'px;overflow:hidden;position:relative;list-style:none;padding:0;margin:0;';

					this.elemInfo.backBtn.style.cssText = this.elemInfo.forwordBtn.style.cssText = "height:"+
					this.elemInfo.ulW+";width:" +this.elemInfo.btnW + 
					'px;font-size:50px;position: absolute;top:0;z-index:99999;line-height: '+
						this.elemInfo.liH+'px;background-color:'+this.initInfo.btnStatetBg+';'+
						'text-align: center;cursor:pointer;color:#fff;font-weight:bold;text-decoration:none;'+
						'user-select:none;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;';

					this.elemInfo.forwordBtn.style.right = '0';
					this.elemInfo.backBtn.style.left = '0';
					this.elemInfo.backBtn.onmouseenter = this.elemInfo.forwordBtn.onmouseenter = function(){
						this.style.background = _this.initInfo.btnActiveBg;
					}
					this.elemInfo.backBtn.onmouseleave = this.elemInfo.forwordBtn.onmouseleave = function(){
						this.style.background = _this.initInfo.btnStatetBg;
					};
					for(var i = 0 ; i < this.elemInfo.len ; i++){
						this.elemInfo.oLi[i].getElementsByTagName('img')[0].style.display = 'block';
						this.elemInfo.oLi[i].style.cssText = 'position:absolute;top:0;left:0;'+
						'margin:0;padding:0;';
					}
				},
				group : function () {
					for(var i = 1 ; i < this.elemInfo.len ; i++) {
						if(this.elemInfo.lGroup.length < this.elemInfo.midd) {
							this.elemInfo.lGroup.push(this.elemInfo.oLi[i]);
						}else {
							this.elemInfo.rGroup.push(this.elemInfo.oLi[i]);
						}
					}
					this.elemInfo.rGroup.reverse();
					
				},
				initSet : function(){
					
					this.elemInfo.oLi[0].style.cssText = 'position:absolute;top:0;left:'+ this.elemInfo.btnW + 
					'px;z-index:' + this.elemInfo.zIdx + ';opacity:1;'+
						'margin:0;padding:0;';

					for(var i = 0 ; i < this.elemInfo.midd;i++){
						var lGroupEle = this.elemInfo.lGroup[i],
							rGroupEle = this.elemInfo.rGroup[i],
							btnW = this.elemInfo.btnW;

						this.initSetLiCss(lGroupEle,i);
						this.initSetLiCss(rGroupEle,i);
						lGroupEle.style.left = (btnW/this.elemInfo.lGroup.length)*(this.elemInfo.midd-i-1) +  'px';
						rGroupEle.style.left = btnW+ this.elemInfo.liW + (btnW/this.elemInfo.rGroup.length)*(i+1) - rGroupEle.offsetWidth + 'px';
					}

				},
				initSetLiCss : function(ele,i){
					var oImg = this.getTag('img',ele)[0],
						scale = this.initInfo.scale,
						method = this.initInfo.method,
						liH = this.elemInfo.liH,
						midd =this.elemInfo.midd;

					oImg.style.width = Math.round(Math.pow(scale,i+1)*this.elemInfo.liW) +'px';
					oImg.style.height = Math.round(Math.pow(scale,i+1)*liH) +'px';
					var offsetH = oImg.offsetHeight;
					ele.style.top = method == 'middle'? ( liH - offsetH)/2 + 'px' : method == 'top'?
						0+'px': method == 'bottom'?  liH-offsetH+'px':( liH - offsetH)/2+'px';
					ele.style.zIndex = midd - i;
					ele.style.opacity = Math.round(Math.pow(scale,(midd-ele.style.zIndex+1))*10)/10;
				},
				setEvent : function(){
					var _this = this;
					this.flag = [];
					for(var i = 0 ; i < this.elemInfo.len; i++) {
						this.flag.push(true);
					}
					this.elemInfo.backBtn.onclick = function(e){
						var e = e || window.event;
						e.preventDefault();
						if( _this.flag.join(' ').indexOf(false) == -1) {
							_this.moveEvent(this);
						}
					}
					this.elemInfo.forwordBtn.onclick = function(e){
						var e = e || window.event;
						e.preventDefault();
						if( _this.flag.join(' ').indexOf(false) == -1) {
							_this.moveEvent(this);
						}
					}
				},
				moveEvent : function (ele){
					for(var i = 0 ; i < this.elemInfo.len; i++){
						if( ele == this.elemInfo.backBtn ) {
							var target = this.elemInfo.oLi[i-1] ? this.elemInfo.oLi[i-1] : this.elemInfo.oLi[this.elemInfo.len-1];
						}else if( ele == this.elemInfo.forwordBtn) {
							var target = this.elemInfo.oLi[i+1] ? this.elemInfo.oLi[i+1] : this.elemInfo.oLi[0];
						}
						obj = {
							width : target.offsetWidth,
							height : target.offsetHeight,
							left : target.offsetLeft,
							top : target.offsetTop,
							opacity : target.style.opacity,
							zIndex : target.style.zIndex,
						};
						this.animate(this.elemInfo.oLi[i],obj,i);
					}
				},
				//自动播放
				autoPlayer : function(auto){
					var _this = this;
					if( auto ) {
						this.autotimer = setInterval(function(){
							if( _this.flag.join(' ').indexOf(false) == -1) {
								_this.moveEvent(_this.elemInfo.forwordBtn);
							}
						},_this.initInfo.timeout);
					}
					
				},
				/*//关闭自动播放
				closeAutoPlayer : function(){
					clearInterval(this.autotimer);
				},*/
				//动画
				animate : function(ele,json,index,fun){
					clearInterval(ele.timer);
					var _this = this;
					this.flag[index] = false;
					ele.timer = setInterval(function(){
						var stop = true;
						for(var attr in json){
							
							var target = json[attr];
							var cur = attr == 'opacity' ? Math.round( parseFloat( _this.self.getStyle.call(null,ele,attr) )*100 )/100 : parseInt( _this.self.getStyle.call(null,ele,attr) );
							var speed = target > cur ? Math.ceil((target-cur)/6) : Math.floor((target-cur)/6);
							if(cur != target) stop = false;

							if( attr == 'opacity' ){
								ele.style.opacity = target;
							}else if( attr == 'zIndex' ){
								ele.style.zIndex = target;
							}
							else{
								if( attr != 'width' && attr != 'height' ){
									ele.style[attr] = cur + speed + 'px';
								}else{
									ele.getElementsByTagName('img')[0].style[attr] = cur + speed + 'px';
								}
							}

						}
						if(stop){
							_this.flag[index] = true;

							clearInterval(ele.timer);
							if(fun){
								fun();
							}
						}
					},30);

				},
				getTag : function(str,parent) {
					return parent.getElementsByTagName(str);
				},
			}
			new Carousel(obj);

		})(elem,obj);
		}
	})
	
	//对象的旋转木马
	Xu.fn.extend({
		carousel: function(obj) {
			for(var i=0; i<this.length; i++) {
				Xu.carousel(this[i], obj);
			}
			return this;
		}
	})




	Xu.fn.init.prototype = Xu.fn;
	window.$ =window.Xu =  Xu;


})();